﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Financial
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            QuoteTicker quoteTicker = new QuoteTicker();
            QuoteTable quoteTable = new QuoteTable();
            ArrayList quoteList = quoteTicker.GetQuote(ConfigurationManager.ReadSetting("Symbols"));
            DataTable dataTable = quoteTable.CreateDataTable("Quote Table", 
                new String[]{"Name", "Ask", "Change and Percent Change", "Days Low", "Days High", 
                                                                "52 Week Low", "52 Week High", "Symbol"}, 
                                                                                                    quoteList);
            dataGridView1.DataSource = dataTable;
        }

        private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                if (dataGridView1.Rows[i].Cells["Change and Percent Change"].Value.ToString().Contains("+"))
                {
                    dataGridView1.Rows[i].Cells["Change and Percent Change"].Style.ForeColor = Color.Green;
                }
                else
                {
                    dataGridView1.Rows[i].Cells["Change and Percent Change"].Style.ForeColor = Color.Red;
                }
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
            Quote quote = ExtensionMethods.CreateQuoteFromRow(row);
            new MoreInformation(quote);
        }

        private void createProfileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Financial.Forms.ProfileForm();
        }
    }
}
